package chenjiuxu.exoplayer;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, CExoPlayerView.OnlayListener {

    private CExoPlayerView playerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        playerView = (CExoPlayerView) findViewById(R.id.activity_main_cepv);
        findViewById(R.id.activity_main_bt).setOnClickListener(this);
        findViewById(R.id.activity_main_bt1).setOnClickListener(this);
        playerView.setPlayListener(this);

        CExoPlayerView.PlaySet playSet = playerView.getPlaySet();
        playSet.isLooping=false;
        playSet.isAutoPlay=true;
        playSet.img_url="http://www.kansight.com/images/14979533266078.jpeg";
        playerView.prepare(playSet);
        //new String[]{"http://192.168.1.100/videos/trace/1/cangfulaojie.mp4", "http://192.168.1.100/videos/trace/1/weigumuchang.mp4", "http://www.kansight.com/videos/1454594246897-SHANGYUAN.mp4"}
        playerView.startPlay("/storage/emulated/0/test.mp4");
    }

    @Override
    protected void onResume() {
        playerView.resume();
        super.onResume();
    }
    @Override
    protected void onPause() {
        playerView.pause();
        super.onPause();
    }
    @Override
    protected void onDestroy() {
        playerView.destroy();
        super.onDestroy();
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.activity_main_bt:
                playerView.pastPlay();
                break;
            case R.id.activity_main_bt1:
                playerView.nextPlay();
                break;
        }
    }

    @Override
    public void currentPlay(int windowIndex) {
        Toast.makeText(this, windowIndex + "", Toast.LENGTH_LONG).show();
    }
    @Override
    public void endPlay() {
        Toast.makeText(this, "播放完成", Toast.LENGTH_LONG).show();
    }
}
